From 8eb28ad65952bbfac408013d0d1367b5f8f18df7 Mon Sep 17 00:00:00 2001 From: calc0000 Date: Tue, 17 Feb 2015 20:39:27 -0500 Subject: [PATCH] Change cargo to explicitly set curl proxy settings only when necessary (when it is specified in either the cargo config or the git config). Otherwise, use curl's logic to pick a proxy (or not). --- src/bin/cargo.rs | 4 ++-- src/cargo/ops/mod.rs | 2 +- src/cargo/ops/registry.rs | 29 ++++++++++++++++++++++++----- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/bin/cargo.rs b/src/bin/cargo.rs index 53c904d34..b69459da7 100644 --- a/src/bin/cargo.rs +++ b/src/bin/cargo.rs @@ -255,8 +255,8 @@ fn init_git_transports(config: &Config) { // Only use a custom transport if a proxy is configured, right now libgit2 // doesn't support proxies and we have to use a custom transport in this // case. The custom transport, however, is not as well battle-tested. - match cargo::ops::http_proxy(config) { - Ok(Some(..)) => {} + match cargo::ops::http_proxy_exists(config) { + Ok(true) => {} _ => return } diff --git a/src/cargo/ops/mod.rs b/src/cargo/ops/mod.rs index b170a050f..6b7341527 100644 --- a/src/cargo/ops/mod.rs +++ b/src/cargo/ops/mod.rs @@ -17,7 +17,7 @@ pub use self::lockfile::{write_lockfile, write_pkg_lockfile}; pub use self::cargo_test::{run_tests, run_benches, TestOptions}; pub use self::cargo_package::package; pub use self::registry::{publish, registry_configuration, RegistryConfig}; -pub use self::registry::{registry_login, search, http_proxy, http_handle}; +pub use self::registry::{registry_login, search, http_proxy_exists, http_handle}; pub use self::registry::{modify_owners, yank, OwnersOptions}; pub use self::cargo_fetch::{fetch}; pub use self::cargo_pkgid::pkgid; diff --git a/src/cargo/ops/registry.rs b/src/cargo/ops/registry.rs index 59754f20b..7ef7fe354 100644 --- a/src/cargo/ops/registry.rs +++ b/src/cargo/ops/registry.rs @@ -173,11 +173,11 @@ pub fn http_handle(config: &Config) -> CargoResult { Ok(handle) } -/// Find a globally configured HTTP proxy if one is available. +/// Find an explicit HTTP proxy if one is available. /// -/// Favor cargo's `http.proxy`, then git's `http.proxy`, then finally a -/// HTTP_PROXY env var. -pub fn http_proxy(config: &Config) -> CargoResult> { +/// Favor cargo's `http.proxy`, then git's `http.proxy`. Proxies specified +/// via environment variables are picked up by libcurl. +fn http_proxy(config: &Config) -> CargoResult> { match try!(config.get_string("http.proxy")) { Some((s, _)) => return Ok(Some(s)), None => {} @@ -191,7 +191,26 @@ pub fn http_proxy(config: &Config) -> CargoResult> { } Err(..) => {} } - Ok(env::var("HTTP_PROXY").ok()) + Ok(None) +} + +/// Determine if an http proxy exists. +/// +/// Checks the following for existence, in order: +/// +/// * cargo's `http.proxy` +/// * git's `http.proxy` +/// * http_proxy env var +/// * HTTP_PROXY env var +/// * https_proxy env var +/// * HTTPS_PROXY env var +pub fn http_proxy_exists(config: &Config) -> CargoResult { + if try!(http_proxy(config)).is_some() { + Ok(true) + } else { + Ok(["http_proxy", "HTTP_PROXY", + "https_proxy", "HTTPS_PROXY"].iter().any(|v| env::var(v).is_ok())) + } } pub fn http_timeout(config: &Config) -> CargoResult> { -- 2.30.2